


/*
1) It takes all TNIC in each year and drop any gvkey that is not in the OD sample (Boardex + ISS)
2) It creates score in t-1, t-2, t-3. Create one dataset per each lagged score.
3) It takes each TNIC-ODsample in each year and merge with OD, OD in t-1,  OD in t-2,
OD in t-3, and OD in t-4
4) It merges with distant peer OD in t-1, t-2, t-3, and t-4
5) Repeat for each year
6) Put all years together
7) It creates percentile bins
8) Plots figure 1 and 2
*/

cd "`c(pwd)'"   // Set working directory to wherever the user placed "replication_package"

* Define global paths relative to the main directory
global main_dir "`c(pwd)'"
global data_dir "$main_dir/data_analysis"
global rawdata_dir "$main_dir/data_raw"
global tables_dir "$main_dir/tables"

* Load data
cd "$data_dir/"

* 1989
cd "$rawdata_dir/"
import delimited tnicall1989.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/40 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1989, replace 

* 1990
cd "$rawdata_dir/"
import delimited tnicall1990.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1990, replace 

* 1991
cd "$rawdata_dir/"
import delimited tnicall1991.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1991, replace 

* 1992
cd "$rawdata_dir/"
import delimited tnicall1992.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1992, replace 

* 1993
cd "$rawdata_dir/"
import delimited tnicall1993.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1993, replace 

* 1994
cd "$rawdata_dir/"
import delimited tnicall1994.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1994, replace 

* 1995
cd "$rawdata_dir/"
import delimited tnicall1995.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1995, replace 

* 1996
cd "$rawdata_dir/"
import delimited tnicall1996.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/100 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1996, replace 

* 1997
cd "$rawdata_dir/"
import delimited tnicall1997.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/150 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1997, replace 

* 1998
cd "$rawdata_dir/"
import delimited tnicall1998.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/150 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1998, replace 

* 1999
cd "$rawdata_dir/"
import delimited tnicall1999.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/150 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_1999, replace 

* 2000
cd "$rawdata_dir/"
import delimited tnicall2000.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/150 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2000, replace 

* 2001
cd "$rawdata_dir/"
import delimited tnicall2001.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2001, replace 

* 2002
cd "$rawdata_dir/"
import delimited tnicall2002.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2002, replace 

* 2003
cd "$rawdata_dir/"
import delimited tnicall2003.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2003, replace 

* 2004
cd "$rawdata_dir/"
import delimited tnicall2004.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2004, replace 

* 2005
cd "$rawdata_dir/"
import delimited tnicall2005.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2005, replace 

* 2006
cd "$rawdata_dir/"
import delimited tnicall2006.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2006, replace 

* 2007
cd "$rawdata_dir/"
import delimited tnicall2007.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2007, replace 

* 2008
cd "$rawdata_dir/"
import delimited tnicall2008.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2008, replace 

* 2009
cd "$rawdata_dir/"
import delimited tnicall2009.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2009, replace 

* 2010
cd "$rawdata_dir/"
import delimited tnicall2010.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2010, replace 

* 2011
cd "$rawdata_dir/"
import delimited tnicall2011.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2011, replace 

* 2012
cd "$rawdata_dir/"
import delimited tnicall2012.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2012, replace 

* 2013
cd "$rawdata_dir/"
import delimited tnicall2013.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2013, replace 

* 2014
cd "$rawdata_dir/"
import delimited tnicall2014.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2014, replace 

* 2015
cd "$rawdata_dir/"
import delimited tnicall2015.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2015, replace 

* 2016
cd "$rawdata_dir/"
import delimited tnicall2016.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2016, replace 

* 2017
cd "$rawdata_dir/"
import delimited tnicall2017.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2017, replace 

* 2018
cd "$rawdata_dir/"
import delimited tnicall2018.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2018, replace 

* 2019
cd "$rawdata_dir/"
import delimited tnicall2019.txt, clear
cd "$data_dir/"
drop if gvkey1==gvkey2
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
* overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_double, unmatched(master)
rename _merge _merge_overlap
tab _merge_overlap
gen od=0
replace od=1 if _merge_overlap==3
* peer of peer overlapping directors 
joinby gvkey1 gvkey2 year using overlapping_directors_pop_double, unmatched(master)
rename _merge _merge_overlap_pop
tab _merge_overlap_pop
gen od_pop=0
replace od_pop=1 if _merge_overlap_pop==3
rename directorid1 linkdirectorid
rename size_odlink1 lsize_odlink1
drop directorid*
drop size*
drop _merge*
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] 
  }
keep score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
save uniquepairwise_2019, replace 


* ALL TOGETHER
cd "$data_dir/"
use uniquepairwise_1989, clear
append using uniquepairwise_1990
append using uniquepairwise_1991
append using uniquepairwise_1992
append using uniquepairwise_1993
append using uniquepairwise_1994
append using uniquepairwise_1995
append using uniquepairwise_1996
append using uniquepairwise_1997
append using uniquepairwise_1998
append using uniquepairwise_1999
append using uniquepairwise_2000
append using uniquepairwise_2001
append using uniquepairwise_2002
append using uniquepairwise_2003
append using uniquepairwise_2004
append using uniquepairwise_2005
append using uniquepairwise_2006
append using uniquepairwise_2007
append using uniquepairwise_2008
append using uniquepairwise_2009
append using uniquepairwise_2010
append using uniquepairwise_2011
append using uniquepairwise_2012
append using uniquepairwise_2013
append using uniquepairwise_2014
append using uniquepairwise_2015
append using uniquepairwise_2016
append using uniquepairwise_2017
append using uniquepairwise_2018
append using uniquepairwise_2019
drop if gvkey1==gvkey2 

sort gvkey1 gvkey2
egen pair=group(gvkey1 gvkey2)
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]
gen gvsum=gvkey1+gvkey2
sort year gvsum gvkey1 gvkey2 od od_pop score
bys year gvsum: gen num=_N
sum num
forvalues i=1/200 {
   drop if gvsum==gvsum[_n-`i'] & gvkey2==gvkey1[_n-`i'] & year==year[_n-`i']
  }

keep pair score gvkey1 gvkey2 year linkdirectorid lsize_odlink1 od od_pop
sort pair year od od_pop score 
drop if pair==pair[_n-1] & year==year[_n-1]

by pair: gen scorel1=score[_n-1] if pair==pair[_n-1] & score[_n-1]!=.
by pair: gen scorel2=score[_n-2] if pair==pair[_n-2] & score[_n-2]!=.
by pair: gen scorel3=score[_n-3] if pair==pair[_n-3] & score[_n-3]!=.

by pair: gen odl1=od[_n-1] if pair==pair[_n-1] & od[_n-1]!=.
by pair: gen odl2=od[_n-2] if pair==pair[_n-2] & od[_n-2]!=.
by pair: gen odl3=od[_n-3] if pair==pair[_n-3] & od[_n-3]!=.

by pair: gen od_popl1=od_pop[_n-1] if pair==pair[_n-1] & od_pop[_n-1]!=.
by pair: gen od_popl2=od_pop[_n-2] if pair==pair[_n-2] & od_pop[_n-2]!=.
by pair: gen od_popl3=od_pop[_n-3] if pair==pair[_n-3] & od_pop[_n-3]!=.

save uniquepairwise, replace

**********************************************************
* BINS

use uniquepairwise, clear

keep pair gvkey1 gvkey2 year score od

bys year: egen p010 = pctile(score) if score!=. , p(01.0)
bys year: egen p020 = pctile(score) if score!=. , p(02.0)
bys year: egen p030 = pctile(score) if score!=. , p(03.0)
bys year: egen p040 = pctile(score) if score!=. , p(04.0)
bys year: egen p050 = pctile(score) if score!=. , p(05.0)
bys year: egen p060 = pctile(score) if score!=. , p(06.0)
bys year: egen p070 = pctile(score) if score!=. , p(07.0)
bys year: egen p080 = pctile(score) if score!=. , p(08.0)
bys year: egen p090 = pctile(score) if score!=. , p(09.0)
bys year: egen p100 = pctile(score) if score!=. , p(10.0)
bys year: egen p110 = pctile(score) if score!=. , p(11.0)
bys year: egen p120 = pctile(score) if score!=. , p(12.0)
bys year: egen p130 = pctile(score) if score!=. , p(13.0)
bys year: egen p140 = pctile(score) if score!=. , p(14.0)
bys year: egen p150 = pctile(score) if score!=. , p(15.0)
bys year: egen p160 = pctile(score) if score!=. , p(16.0)
bys year: egen p170 = pctile(score) if score!=. , p(17.0)
bys year: egen p180 = pctile(score) if score!=. , p(18.0)
bys year: egen p190 = pctile(score) if score!=. , p(19.0)
bys year: egen p200 = pctile(score) if score!=. , p(20.0)
bys year: egen p210 = pctile(score) if score!=. , p(21.0)
bys year: egen p220 = pctile(score) if score!=. , p(22.0)
bys year: egen p230 = pctile(score) if score!=. , p(23.0)
bys year: egen p240 = pctile(score) if score!=. , p(24.0)
bys year: egen p250 = pctile(score) if score!=. , p(25.0)
bys year: egen p260 = pctile(score) if score!=. , p(26.0)
bys year: egen p270 = pctile(score) if score!=. , p(27.0)
bys year: egen p280 = pctile(score) if score!=. , p(28.0)
bys year: egen p290 = pctile(score) if score!=. , p(29.0)
bys year: egen p300 = pctile(score) if score!=. , p(30.0)
bys year: egen p310 = pctile(score) if score!=. , p(31.0)
bys year: egen p320 = pctile(score) if score!=. , p(32.0)
bys year: egen p330 = pctile(score) if score!=. , p(33.0)
bys year: egen p340 = pctile(score) if score!=. , p(34.0)
bys year: egen p350 = pctile(score) if score!=. , p(35.0)
bys year: egen p360 = pctile(score) if score!=. , p(36.0)
bys year: egen p370 = pctile(score) if score!=. , p(37.0)
bys year: egen p380 = pctile(score) if score!=. , p(38.0)
bys year: egen p390 = pctile(score) if score!=. , p(39.0)
bys year: egen p400 = pctile(score) if score!=. , p(40.0)
bys year: egen p410 = pctile(score) if score!=. , p(41.0)
bys year: egen p420 = pctile(score) if score!=. , p(42.0)
bys year: egen p430 = pctile(score) if score!=. , p(43.0)
bys year: egen p440 = pctile(score) if score!=. , p(44.0)
bys year: egen p450 = pctile(score) if score!=. , p(45.0)
bys year: egen p460 = pctile(score) if score!=. , p(46.0)
bys year: egen p470 = pctile(score) if score!=. , p(47.0)
bys year: egen p480 = pctile(score) if score!=. , p(48.0)
bys year: egen p490 = pctile(score) if score!=. , p(49.0)
bys year: egen p500 = pctile(score) if score!=. , p(50.0)
bys year: egen p510 = pctile(score) if score!=. , p(51.0)
bys year: egen p520 = pctile(score) if score!=. , p(52.0)
bys year: egen p530 = pctile(score) if score!=. , p(53.0)
bys year: egen p540 = pctile(score) if score!=. , p(54.0)
bys year: egen p550 = pctile(score) if score!=. , p(55.0)
bys year: egen p560 = pctile(score) if score!=. , p(56.0)
bys year: egen p570 = pctile(score) if score!=. , p(57.0)
bys year: egen p580 = pctile(score) if score!=. , p(58.0)
bys year: egen p590 = pctile(score) if score!=. , p(59.0)
bys year: egen p600 = pctile(score) if score!=. , p(60.0)
bys year: egen p610 = pctile(score) if score!=. , p(61.0)
bys year: egen p620 = pctile(score) if score!=. , p(62.0)
bys year: egen p630 = pctile(score) if score!=. , p(63.0)
bys year: egen p640 = pctile(score) if score!=. , p(64.0)
bys year: egen p650 = pctile(score) if score!=. , p(65.0)
bys year: egen p660 = pctile(score) if score!=. , p(66.0)
bys year: egen p670 = pctile(score) if score!=. , p(67.0)
bys year: egen p680 = pctile(score) if score!=. , p(68.0)
bys year: egen p690 = pctile(score) if score!=. , p(69.0)
bys year: egen p700 = pctile(score) if score!=. , p(70.0)
bys year: egen p710 = pctile(score) if score!=. , p(71.0)
bys year: egen p720 = pctile(score) if score!=. , p(72.0)
bys year: egen p730 = pctile(score) if score!=. , p(73.0)
bys year: egen p740 = pctile(score) if score!=. , p(74.0)
bys year: egen p750 = pctile(score) if score!=. , p(75.0)
bys year: egen p760 = pctile(score) if score!=. , p(76.0)
bys year: egen p770 = pctile(score) if score!=. , p(77.0)
bys year: egen p780 = pctile(score) if score!=. , p(78.0)
bys year: egen p790 = pctile(score) if score!=. , p(79.0)
bys year: egen p800 = pctile(score) if score!=. , p(80.0)
bys year: egen p810 = pctile(score) if score!=. , p(81.0)
bys year: egen p820 = pctile(score) if score!=. , p(82.0)
bys year: egen p830 = pctile(score) if score!=. , p(83.0)
bys year: egen p840 = pctile(score) if score!=. , p(84.0)
bys year: egen p850 = pctile(score) if score!=. , p(85.0)
bys year: egen p860 = pctile(score) if score!=. , p(86.0)
bys year: egen p870 = pctile(score) if score!=. , p(87.0)
bys year: egen p880 = pctile(score) if score!=. , p(88.0)
bys year: egen p890 = pctile(score) if score!=. , p(89.0)
bys year: egen p900 = pctile(score) if score!=. , p(90.0)
bys year: egen p910 = pctile(score) if score!=. , p(91.0)
bys year: egen p920 = pctile(score) if score!=. , p(92.0)
bys year: egen p930 = pctile(score) if score!=. , p(93.0)
bys year: egen p940 = pctile(score) if score!=. , p(94.0)

bys year: egen p950 = pctile(score) if score!=. , p(95.0)
bys year: egen p951 = pctile(score) if score!=. , p(95.1)
bys year: egen p952 = pctile(score) if score!=. , p(95.2)
bys year: egen p953 = pctile(score) if score!=. , p(95.3)
bys year: egen p954 = pctile(score) if score!=. , p(95.4)
bys year: egen p955 = pctile(score) if score!=. , p(95.5)
bys year: egen p956 = pctile(score) if score!=. , p(95.6)
bys year: egen p957 = pctile(score) if score!=. , p(95.7)
bys year: egen p958 = pctile(score) if score!=. , p(95.8)
bys year: egen p959 = pctile(score) if score!=. , p(95.9)
bys year: egen p960 = pctile(score) if score!=. , p(96.0)
bys year: egen p961 = pctile(score) if score!=. , p(96.1)
bys year: egen p962 = pctile(score) if score!=. , p(96.2)
bys year: egen p963 = pctile(score) if score!=. , p(96.3)
bys year: egen p964 = pctile(score) if score!=. , p(96.4)
bys year: egen p965 = pctile(score) if score!=. , p(96.5)
bys year: egen p966 = pctile(score) if score!=. , p(96.6)
bys year: egen p967 = pctile(score) if score!=. , p(96.7)
bys year: egen p968 = pctile(score) if score!=. , p(96.8)
bys year: egen p969 = pctile(score) if score!=. , p(96.9)
bys year: egen p970 = pctile(score) if score!=. , p(97.0)
bys year: egen p971 = pctile(score) if score!=. , p(97.1)
bys year: egen p972 = pctile(score) if score!=. , p(97.2)
bys year: egen p973 = pctile(score) if score!=. , p(97.3)
bys year: egen p974 = pctile(score) if score!=. , p(97.4)
bys year: egen p975 = pctile(score) if score!=. , p(97.5)
bys year: egen p976 = pctile(score) if score!=. , p(97.6)
bys year: egen p977 = pctile(score) if score!=. , p(97.7)
bys year: egen p978 = pctile(score) if score!=. , p(97.8)
bys year: egen p979 = pctile(score) if score!=. , p(97.9)
bys year: egen p980 = pctile(score) if score!=. , p(98.0)
bys year: egen p981 = pctile(score) if score!=. , p(98.1)
bys year: egen p982 = pctile(score) if score!=. , p(98.2)
bys year: egen p983 = pctile(score) if score!=. , p(98.3)
bys year: egen p984 = pctile(score) if score!=. , p(98.4)
bys year: egen p985 = pctile(score) if score!=. , p(98.5)
bys year: egen p986 = pctile(score) if score!=. , p(98.6)
bys year: egen p987 = pctile(score) if score!=. , p(98.7)
bys year: egen p988 = pctile(score) if score!=. , p(98.8)
bys year: egen p989 = pctile(score) if score!=. , p(98.9)
bys year: egen p990 = pctile(score) if score!=. , p(99.0)
bys year: egen p991 = pctile(score) if score!=. , p(99.1)
bys year: egen p992 = pctile(score) if score!=. , p(99.2)
bys year: egen p993 = pctile(score) if score!=. , p(99.3)
bys year: egen p994 = pctile(score) if score!=. , p(99.4)
bys year: egen p995 = pctile(score) if score!=. , p(99.5)
bys year: egen p996 = pctile(score) if score!=. , p(99.6)
bys year: egen p997 = pctile(score) if score!=. , p(99.7)
bys year: egen p998 = pctile(score) if score!=. , p(99.8)
bys year: egen p999 = pctile(score) if score!=. , p(99.9)

save binsplotdata, replace




*******************************************************************************
*******************************************************************************
*******************************************************************************




use binsplotdata, clear

drop if score<=p520
keep gvkey1  gvkey2  pair od score year p520 p530 p540 p550 p560 p570 p580 p590 p600 p610 p620 p630 p640 p650 p660 p670 p680 p690 p700 p710 p720 p730 p740 p750 p760 p770 p780 p790 p800 p810 p820 p830 p840 p850 p860 p870 p880 p890 p900 p910 p920 p930 p940 p950 p951 p952 p953 p954 p955 p956 p957 p958 p959 p960 p961 p962 p963 p964 p965 p966 p967 p968 p969 p970 p971 p972 p973 p974 p975 p976 p977 p978 p979 p980 p981 p982 p983 p984 p985 p986 p987 p988 p989 p990 p991 p992 p993 p994 p995 p996 p997 p998 p999
rename gvkey1 gvkey
joinby gvkey year using gvkey_sic3, unmatched(master)
drop _merge sic
drop if sic3>=600 & sic3<=699
drop sic3
joinby gvkey year using totalsim4, unmatched(master)
drop _merge 
rename tsim4 tsim4_1
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using gvkey_sic3, unmatched(master)
drop _merge sic
drop if sic3>=600 & sic3<=699
drop sic3
joinby gvkey year using totalsim4, unmatched(master)
drop _merge 
rename tsim4 tsim4_2
rename gvkey gvkey2
gen totalsimtn4= (tsim4_1+tsim4_2)/2
drop tsim4_1 tsim4_2
drop gvkey1  gvkey2
sort pair year score
bys pair year: drop if pair==pair[_n-1] & year==year[_n-1]

bys year: egen totalsimtn4p50 = pctile(totalsimtn4) if totalsimtn4!=. , p(50)
gen hightnsim=0  & totalsimtn4!=.
replace hightnsim=1 if totalsimtn4>=totalsimtn4p50 & totalsimtn4!=.
drop totalsimtn4p50
keep if hightnsim==1
save binsplotdata2TS, replace


* 1989
use binsplotdata2TS, clear
keep if year==1989
egen bin530=mean(od) if score>=p530 & score<p540 
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1989nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1989nobanks, replace

* 1990
use binsplotdata2TS, clear
keep if year==1990
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1990nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1990nobanks, replace

* 1991
use binsplotdata2TS, clear
keep if year==1991
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1991nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1991nobanks, replace

* 1992
use binsplotdata2TS, clear
keep if year==1992
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1992nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1992nobanks, replace

* 1993
use binsplotdata2TS, clear
keep if year==1993
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1993nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1993nobanks, replace

* 1994
use binsplotdata2TS, clear
keep if year==1994
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1994nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1994nobanks, replace

* 1995
use binsplotdata2TS, clear
keep if year==1995
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1995nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1995nobanks, replace

* 1996
use binsplotdata2TS, clear
keep if year==1996
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1996nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1996nobanks, replace

* 1997
use binsplotdata2TS, clear
keep if year==1997
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1997nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1997nobanks, replace

* 1998
use binsplotdata2TS, clear
keep if year==1998
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1998nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1998nobanks, replace

* 1999
use binsplotdata2TS, clear
keep if year==1999
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins1999nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins1999nobanks, replace

* 2000
use binsplotdata2TS, clear
keep if year==2000
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2000nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2000nobanks, replace

* 2001
use binsplotdata2TS, clear
keep if year==2001
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2001nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2001nobanks, replace

* 2002
use binsplotdata2TS, clear
keep if year==2002
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2002nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2002nobanks, replace

* 2003
use binsplotdata2TS, clear
keep if year==2003
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2003nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2003nobanks, replace

* 2004
use binsplotdata2TS, clear
keep if year==2004
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2004nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2004nobanks, replace

* 2005
use binsplotdata2TS, clear
keep if year==2005
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2005nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2005nobanks, replace

* 2006
use binsplotdata2TS, clear
keep if year==2006
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2006nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2006nobanks, replace

* 2007
use binsplotdata2TS, clear
keep if year==2007
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2007nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2007nobanks, replace

* 2008
use binsplotdata2TS, clear
keep if year==2008
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2008nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2008nobanks, replace

* 2009
use binsplotdata2TS, clear
keep if year==2009
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2009nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2009nobanks, replace

* 2010
use binsplotdata2TS, clear
keep if year==2010
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2010nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2010nobanks, replace

* 2011
use binsplotdata2TS, clear
keep if year==2011
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2011nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2011nobanks, replace

* 2012
use binsplotdata2TS, clear
keep if year==2012
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2012nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2012nobanks, replace

* 2013
use binsplotdata2TS, clear
keep if year==2013
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2013nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2013nobanks, replace

* 2014
use binsplotdata2TS, clear
keep if year==2014
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2014nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2014nobanks, replace

* 2015
use binsplotdata2TS, clear
keep if year==2015
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2015nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2015nobanks, replace

* 2016
use binsplotdata2TS, clear
keep if year==2016
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2016nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2016nobanks, replace

* 2017
use binsplotdata2TS, clear
keep if year==2017
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2017nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2017nobanks, replace

* 2018
use binsplotdata2TS, clear
keep if year==2018
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2018nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2018nobanks, replace

* 2019
use binsplotdata2TS, clear
keep if year==2019
egen bin530=mean(od) if score>=p530 & score<p540
egen bin540=mean(od) if score>=p540 & score<p550
egen bin550=mean(od) if score>=p550 & score<p560
egen bin560=mean(od) if score>=p560 & score<p570
egen bin570=mean(od) if score>=p570 & score<p580
egen bin580=mean(od) if score>=p580 & score<p590
egen bin590=mean(od) if score>=p590 & score<p600
egen bin600=mean(od) if score>=p600 & score<p610
egen bin610=mean(od) if score>=p610 & score<p620
egen bin620=mean(od) if score>=p620 & score<p630
egen bin630=mean(od) if score>=p630 & score<p640
egen bin640=mean(od) if score>=p640 & score<p650
egen bin650=mean(od) if score>=p650 & score<p660
egen bin660=mean(od) if score>=p660 & score<p670
egen bin670=mean(od) if score>=p670 & score<p680
egen bin680=mean(od) if score>=p680 & score<p690
egen bin690=mean(od) if score>=p690 & score<p700
egen bin700=mean(od) if score>=p700 & score<p710
egen bin710=mean(od) if score>=p710 & score<p720
egen bin720=mean(od) if score>=p720 & score<p730
egen bin730=mean(od) if score>=p730 & score<p740
egen bin740=mean(od) if score>=p740 & score<p750
egen bin750=mean(od) if score>=p750 & score<p760
egen bin760=mean(od) if score>=p760 & score<p770
egen bin770=mean(od) if score>=p770 & score<p780
egen bin780=mean(od) if score>=p780 & score<p790
egen bin790=mean(od) if score>=p790 & score<p800
egen bin800=mean(od) if score>=p800 & score<p810
egen bin810=mean(od) if score>=p810 & score<p820
egen bin820=mean(od) if score>=p820 & score<p830
egen bin830=mean(od) if score>=p830 & score<p840
egen bin840=mean(od) if score>=p840 & score<p850
egen bin850=mean(od) if score>=p850 & score<p860
egen bin860=mean(od) if score>=p860 & score<p870
egen bin870=mean(od) if score>=p870 & score<p880
egen bin880=mean(od) if score>=p880 & score<p890
egen bin890=mean(od) if score>=p890 & score<p900
egen bin900=mean(od) if score>=p900 & score<p910
egen bin910=mean(od) if score>=p910 & score<p920
egen bin920=mean(od) if score>=p920 & score<p930
egen bin930=mean(od) if score>=p930 & score<p940
egen bin940=mean(od) if score>=p940 & score<p950
egen bin950=mean(od) if score>=p950 & score<p960
egen bin960=mean(od) if score>=p960 & score<p970
egen bin970=mean(od) if score>=p970 & score<p980
egen bin980=mean(od) if score>=p980 & score<p990
egen bin990=mean(od) if score>=p990 & score!=.
egen clbin950=mean(od) if score>=p950 & score<p951
egen clbin951=mean(od) if score>=p951 & score<p952
egen clbin952=mean(od) if score>=p952 & score<p953
egen clbin953=mean(od) if score>=p953 & score<p954
egen clbin954=mean(od) if score>=p954 & score<p955
egen clbin955=mean(od) if score>=p955 & score<p956
egen clbin956=mean(od) if score>=p956 & score<p957
egen clbin957=mean(od) if score>=p957 & score<p958
egen clbin958=mean(od) if score>=p958 & score<p959
egen clbin959=mean(od) if score>=p959 & score<p960
egen clbin960=mean(od) if score>=p960 & score<p961
egen clbin961=mean(od) if score>=p961 & score<p962
egen clbin962=mean(od) if score>=p962 & score<p963
egen clbin963=mean(od) if score>=p963 & score<p964
egen clbin964=mean(od) if score>=p964 & score<p965
egen clbin965=mean(od) if score>=p965 & score<p966
egen clbin966=mean(od) if score>=p966 & score<p967
egen clbin967=mean(od) if score>=p967 & score<p968
egen clbin968=mean(od) if score>=p968 & score<p969
egen clbin969=mean(od) if score>=p969 & score<p970
egen clbin970=mean(od) if score>=p970 & score<p971
egen clbin971=mean(od) if score>=p971 & score<p972
egen clbin972=mean(od) if score>=p972 & score<p973
egen clbin973=mean(od) if score>=p973 & score<p974
egen clbin974=mean(od) if score>=p974 & score<p975
egen clbin975=mean(od) if score>=p975 & score<p976
egen clbin976=mean(od) if score>=p976 & score<p977
egen clbin977=mean(od) if score>=p977 & score<p978
egen clbin978=mean(od) if score>=p978 & score<p979
egen clbin979=mean(od) if score>=p979 & score<p980
egen clbin980=mean(od) if score>=p980 & score<p981
egen clbin981=mean(od) if score>=p981 & score<p982
egen clbin982=mean(od) if score>=p982 & score<p983
egen clbin983=mean(od) if score>=p983 & score<p984
egen clbin984=mean(od) if score>=p984 & score<p985
egen clbin985=mean(od) if score>=p985 & score<p986
egen clbin986=mean(od) if score>=p986 & score<p987
egen clbin987=mean(od) if score>=p987 & score<p988
egen clbin988=mean(od) if score>=p988 & score<p989
egen clbin989=mean(od) if score>=p989 & score<p900
egen clbin990=mean(od) if score>=p990 & score<p991
egen clbin991=mean(od) if score>=p991 & score<p992
egen clbin992=mean(od) if score>=p992 & score<p993
egen clbin993=mean(od) if score>=p993 & score<p994
egen clbin994=mean(od) if score>=p994 & score<p995
egen clbin995=mean(od) if score>=p995 & score<p996
egen clbin996=mean(od) if score>=p996 & score<p997
egen clbin997=mean(od) if score>=p997 & score<p998
egen clbin998=mean(od) if score>=p998 & score<p999
egen clbin999=mean(od) if score>=p999 & score!=.
save binsplotdatatest, replace
collapse (mean) bin*, by(year)
reshape long bin, i(year) j(pct)
save bins2019nobanks, replace
use binsplotdatatest, clear
collapse (mean) clbin*, by(year)
reshape long clbin, i(year) j(pct)
save clbins2019nobanks, replace



use bins1989nobanks, clear
append using bins1990nobanks
append using bins1991nobanks
append using bins1992nobanks
append using bins1993nobanks
append using bins1994nobanks
append using bins1995nobanks
append using bins1996nobanks
append using bins1997nobanks
append using bins1998nobanks
append using bins1999nobanks
append using bins2000nobanks
append using bins2001nobanks
append using bins2002nobanks
append using bins2003nobanks
append using bins2004nobanks
append using bins2005nobanks
append using bins2006nobanks
append using bins2007nobanks
append using bins2008nobanks
append using bins2009nobanks
append using bins2010nobanks
append using bins2011nobanks
append using bins2012nobanks
append using bins2013nobanks
append using bins2014nobanks
append using bins2015nobanks
append using bins2016nobanks
append using bins2017nobanks
append using bins2018nobanks
append using bins2019nobanks
save bins1989_2019nobanksTS, replace

use clbins1989nobanks, clear
append using clbins1990nobanks
append using clbins1991nobanks
append using clbins1992nobanks
append using clbins1993nobanks
append using clbins1994nobanks
append using clbins1995nobanks
append using clbins1996nobanks
append using clbins1997nobanks
append using clbins1998nobanks
append using clbins1999nobanks
append using clbins2000nobanks
append using clbins2001nobanks
append using clbins2002nobanks
append using clbins2003nobanks
append using clbins2004nobanks
append using clbins2005nobanks
append using clbins2006nobanks
append using clbins2007nobanks
append using clbins2008nobanks
append using clbins2009nobanks
append using clbins2010nobanks
append using clbins2011nobanks
append using clbins2012nobanks
append using clbins2013nobanks
append using clbins2014nobanks
append using clbins2015nobanks
append using clbins2016nobanks
append using clbins2017nobanks
append using clbins2018nobanks
append using clbins2019nobanks
save clbins1989_2019nobanksTS, replace




* PLOT 1

use bins1989_2019nobanksTS, clear
replace pct=pct/10
sort pct year
bys pct: egen bin_1989_2019=mean(bin)
bys pct: egen bin_1989_1999=mean(bin) if year<=1999
bys pct: egen bin_2000_2009=mean(bin) if year>=2000 & year<=2009
bys pct: egen bin_2010_2019=mean(bin) if year>=2010 
bys pct: egen bin_2015_2019=mean(bin) if year>=2015 & year<=2019
bys pct: egen bin_2010_2014=mean(bin) if year>=2010 & year<=2014
bys pct: egen bin_2005_2009=mean(bin) if year>=2005 & year<=2009
bys pct: egen bin_2000_2004=mean(bin) if year>=2000 & year<=2004
bys pct: egen bin_1995_1999=mean(bin) if year>=1995 & year<=1999
bys pct: egen bin_1989_1994=mean(bin) if year>=1989 & year<=1994
collapse (mean)  bin_1989_2019 bin_1989_1999 bin_2000_2009 bin_2010_2019 bin_2015_2019 bin_2010_2014 bin_2005_2009 bin_2000_2004 bin_1995_1999 bin_1989_1994, by(pct)


twoway line bin_1989_2019 pct  ,  lcolor(navy) lwidth(medium) graphregion(color(white)) legend(lab(1 "Probability of Overlapping director")) title("Probability of Overlapping director") ytitle("") xtitle("Product Similarity Percentile")	


* PLOT 2: close-up tp pct95

use clbins1989_2019nobanksTS, clear
sort pct year
bys pct: egen bin_1989_2019=mean(clbin)
bys pct: egen bin_1989_1999=mean(clbin) if year<=1999
bys pct: egen bin_2000_2009=mean(clbin) if year>=2000 & year<=2009
bys pct: egen bin_2010_2019=mean(clbin) if year>=2010 
bys pct: egen bin_2015_2019=mean(clbin) if year>=2015 & year<=2019
bys pct: egen bin_2010_2014=mean(clbin) if year>=2010 & year<=2014
bys pct: egen bin_2005_2009=mean(clbin) if year>=2005 & year<=2009
bys pct: egen bin_2000_2004=mean(clbin) if year>=2000 & year<=2004
bys pct: egen bin_1995_1999=mean(clbin) if year>=1995 & year<=1999
bys pct: egen bin_1989_1994=mean(clbin) if year>=1989 & year<=1994
collapse (mean)  bin_1989_2019 bin_1989_1999 bin_2000_2009 bin_2010_2019 bin_2015_2019 bin_2010_2014 bin_2005_2009 bin_2000_2004 bin_1995_1999 bin_1989_1994, by(pct)


twoway line bin_1989_2019 pct ,  lcolor(navy) lwidth(medium) graphregion(color(white)) legend(lab(1 "Probability of Overlapping director")) title("Probability of Overlapping director") ytitle("") xtitle("Product Similarity Percentile")	


